package oracle.apps.financials.collection.listener;

import greendroid.widget.ItemAdapter;
import greendroid.widget.item.Item;
import greendroid.widget.item.SubtextItem;

import java.util.ArrayList;
import java.util.List;

import oracle.apps.financials.collection.R;
import oracle.apps.financials.collection.po.Customer;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.PopupWindow;

public class PercentCurrentParameterWindowListener extends BaseOnClickListener {

	private ListView listView;

	private ItemAdapter adapter;

	private BusinsessUnitWindowListener businsessUnitWindowListener;

	private View layout;

	public PercentCurrentParameterWindowListener(Context context, Customer customer, Handler mHandler) {
		super(context, R.layout.add_parameter, customer, mHandler);
		businsessUnitWindowListener = new BusinsessUnitWindowListener(context, customer, mHandler);
	}

	public List<Item> getItemList() {
		List<Item> items = new ArrayList<Item>();

		items.add(new SubtextItem("Business Unit", businsessUnitWindowListener.getAdapter().isSelectedAll() ? "All" : businsessUnitWindowListener
				.getAdapter().getSelectedCount() + " Selected "));
		// items.add(new SubtextItem("Business Unit", "All"));
		return items;
	}

	@Override
	public void onClick(View parent) {
		if (popupWindow == null) {
			initPopupwindow();
		}
		layout = parent;
		popupWindow.showAsDropDown(parent, -80, 1);
	}

	public void initPopupwindow() {
		popupWindow = new PopupWindow(popupWindowView, 200, 220);
		listView = (ListView) popupWindowView.findViewById(R.id.param_list);

		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// if (position == 1)
				{

					PercentCurrentParameterWindowListener.this.dismissPopupWindow();
					businsessUnitWindowListener.showPopupwindow(layout);

				}
			}

		});
		adapter = new ItemAdapter(context, getItemList());
		listView.setAdapter(adapter);
		processButtonEvent();
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());

	}

	public void processButtonEvent() {

	}

}
